﻿@{
    Layout = null;
    bool isLogin = HttpContext.Current.User.Identity.IsAuthenticated;
    var notic = ViewData["notic"] as Pay.DTO.notice_dto;
    var merchantlist = ViewData["merchantlist"] as List<Pay.DTO.merch_dto>;
    var hongzhuan = ViewData["hongzhuan"] as Pay.DTO.red_rank_dto;
    var mali = ViewData["mali"] as Pay.DTO.red_rank_dto;
    var person = ViewData["person"] as Pay.DTO.user_red_dto;
    var user_red = ViewData["user_red"] as Pay.DTO.red_user_dto;

    var red = ViewData["red"] as List<Pay.DTO.redrecorddetail_dto>;
    var adList = ViewData["adList"] as List<Pay.DTO.ad_dto>;
    string site_img = ViewData["site_img"] as string;
    var token_user_info = ViewData["TokenUser"] as token_user_info;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>拓垦</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0,maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit" />
    <link rel="stylesheet" href="~/Content/css/base.css" />
    <link rel="stylesheet" href="~/Content/css/tuoken.css" />
    <link href="~/Content/css/wswd.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/Content/css/swiper-4.2.2.min.css">
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/js/base.js"></script>
    <script type="text/javascript" src="~/Content/js/swiper-4.2.2.min.js"></script>
    <script type="text/javascript" src="~/Content/js/jquery.fly.min.js"></script>
    <script src="~/Content/js/layer/1.9.3/layer.js"></script>
</head>
<body>
    <div class="bodyct">
        <div class="mining">
            <div class="noticect" onclick="location='/notic/NoticeMessge'">
                <div id="notice" class="notice">
                    <div id="noticeinfo">
                        @if (notic != null) {
                            <text>@notic.title</text>
                        }
                    </div>
                    <div id="noticeloop"></div>
                </div>
            </div>
            <div class="physical">
                <p>
                    <i class="diamondico" id="cartoonend"></i>
                    <span>红钻</span>
                    <span id="redsum">@if (isLogin) {<text>@user_red.present_red_drill</text>} else { <text>0</text>} </span>
                </p>
                <p>
                    <i class="soupico"></i>
                    <span>马力</span>
                    <span>@if (isLogin) {<text>@user_red.horse_power</text>} else { <text>0</text>}</span>
                </p>
            </div>

            @if (isLogin) {

                if (red != null && red.Count >= 0) {
                    int rcount = red.Count; int icount = rcount >= 10 ? 10 : rcount; int scount = rcount >= 20 ? 20 : rcount - 10;
                    if (rcount == 0) {
                        <div>
                            <div class="scoop_content scoop_content0">
                                <i class="scoop"></i>
                                <span>@(token_user_info.is_verify_no_card ? "生产中" : "需要实名")</span>
                                <p style="display:none"></p>
                            </div>
                        </div>
                    }

                    <div id="red1">
                        @for (var index = 0; index < icount; index++) {
                            <div class="scoop_content scoop_content@(index + 1) red" id="@red[index].id">
                                <i class="scoop"></i>
                                <span>@red[index].red_drill</span>
                                <p style="display:none">@red[index].id</p>
                            </div>


                        }
                    </div>

                    if (rcount > 10) {
                        <div style="display:none" id="red2">
                            @for (var index = 0; index < scount - 10; index++) {
                                <div class="scoop_content scoop_content@(index + 1) red" id="@red[index+10].id">
                                    <i class="scoop"></i>
                                    <span>@red[index + 10].red_drill</span>
                                    <p style="display:none">@red[index + 10].id</p>
                                </div>}
                        </div>
                    }
                    if (rcount > 20) {
                        <div style="display:none" id="red3">
                            @for (var index = 0; index < rcount - 20; index++) {
                                <div class="scoop_content scoop_content@(index + 1) red" id="@red[index+20].id">
                                    <i class="scoop"></i>
                                    <span>@red[index + 20].red_drill</span>
                                    <p style="display:none">@red[index + 20].id</p>
                                </div>}
                        </div>
                    }
                }
            } else {
                <div>
                    <div class="scoop_content scoop_content0" onclick="location='/home/login'">
                        <i class="scoop"></i>
                        <span>登录后领取</span>
                        <p style="display:none"></p>
                    </div>
                </div>
            }


            <!-- 获得马力 -->
                <div class="scoop_link">
                    <a href="/task/list">
                        <i class="agin_ico1"></i>
                        <span>获得马力</span>
                    </a>
                    <a href="/Consumption/Index">
                        <i class="agin_ico2"></i>
                        <span>兑换消费</span>
                    </a>
                    <a href="/shopinfo/ShowShop">
                        <i class="agin_ico2"></i>
                        <span>节点商城</span>
                    </a>
                    <a href="/BazaarProduct/Index">
                        <i class="agin_ico2"></i>
                        <span>集市</span>
                    </a>
                    <a href="/task/InviteRegister" class="invite">
                        <i class="agin_ico3"></i>
                        <span>邀请好友</span>
                    </a>
                </div>
            @*<div class="personico">挖矿图片</div>*@
        </div>
        <!-- 数据排行 -->
        <div class="ranking">
            <h2>
                <label>数据排行</label>
                <span class="time">更新于 @DateTime.Now.ToString("yyyy-MM-dd HH") 点</span>
            </h2>
            <p>
                我的马力排行
                <span>@if (isLogin) {<text>@person.h_no</text>} else { <text>0</text>}</span>
            </p>
            <p>
                我的红钻排行
                <span>@if (isLogin) {<text>@person.r_no</text>} else { <text>0</text>}</span>
            </p>
        </div>
        <!-- 商家 -->
        @*<div class="merchant">
            <div class="merchant_link">
                <div class="merchant_title">
                    <div class="merchant_titlect">
                        <div class="lf"></div>
                        <span>商家</span>
                        <div class="rg"></div>
                    </div>
                </div>
                @if (merchantlist != null && merchantlist.Count > 0) {
                    for (var index = 0; index < merchantlist.Count; index++) {
                        var i = 1;
                        if (i < 3) {
                            <a href="/Merchant/Merchant/?Id=@merchantlist[index].id">
                                <img src="@string.Format("{0}{1}",site_img,merchantlist[index].logo_url)" class="ico">@merchantlist[index].merch_name
                            </a>
                        }
                        i++;
                    }
                }
                <a href="/Merchant/MerchantList" class="more">
                    <span>查看更多商家</span>
                </a>
            </div>
        </div>*@
        <!-- banner -->
        <div class="banner">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    @if (adList != null && adList.Count() > 0) {
                        foreach (var ad in adList) {
                            <div class="swiper-slide">
                                <a href="@(ad.link_url == null ? "javascript:void(0)" : string.Format("javascript:clickAd('{0}','{1}')", ad.id, ad.link_url))">
                                    <img src="@(site_img + ad.img_url)" alt="">
                                </a>
                            </div>
                        }
                    }
                </div>
                <div class="swiper-pagination"></div>
            </div>
        </div>
        <!-- 红钻排行榜 -->
        <div class="red_ranking">
            <h2>
                <label>红钻排行榜</label>
                <span class="time">更新于 @hongzhuan.datetime 点</span>
                <span class="horse" id="switch_ranking">
                    <em class="horseinfo">按马力排行</em>
                    <i></i>
                </span>
            </h2>
            <!-- 红钻排行 -->
            <ul id="redranking">
                <li class="title">
                    <label>名次</label>
                    <label>用户名</label>
                    <label>总红钻</label>
                </li>

                @if (hongzhuan != null && hongzhuan.list.Count > 0) {
                    for (int index = 0, count = hongzhuan.list.Count; index < count; index++) {
                        <li>
                            <label>
                                @if (index == 0) {
                                    <i class="one"></i>
                                } else if (index == 1) {
                                    <i class="two"></i>
                                } else if (index == 2) {
                                    <i class="free"></i>
                                } else if (index >= 3) {
                                    <i>@(index + 1)</i>
                                }
                            </label>
                            <label>@hongzhuan.list[index].nick_name</label>
                            <label>@hongzhuan.list[index].red_drill</label>
                        </li>

                    }
                }


            </ul>
            <!-- 马力排行 -->
            <ul id="horseranking">
                <li class="title">
                    <label>名次</label>
                    <label>用户名</label>
                    <label>马力值</label>
                </li>
                @if (mali != null && mali.list.Count > 0) {
                    for (int index = 0, count = mali.list.Count; index < count; index++) {
                        <li>
                            <label>
                                @if (index == 0) {
                                    <i class="one"></i>
                                } else if (index == 1) {
                                    <i class="two"></i>
                                } else if (index == 2) {
                                    <i class="free"></i>
                                } else if (index >= 3) {
                                    <i>@(index + 1)</i>
                                }
                            </label>
                            <label>@mali.list[index].nick_name</label>
                            <label>@mali.list[index].horse_power</label>
                        </li>

                    }
                }
            </ul>
        </div>
    </div>
    <!--底部-->
    <div class="footer">
        <a href="/Home/Index" class="on">
            <i></i>
            <span>基地</span>
        </a>
        <a href="/DistributionMall/Index">
            <i></i>
            <span>云商城</span>
        </a>
        <a href="/ProductTokenMaker/Index">
            <i></i>
            <span>创客导购</span>
        </a>
        @*<a href="/Consumption/Index">
            <i></i>
            <span>发现</span>
        </a>*@

        <a href="/User/My">
            <i></i>
            <span>我的</span>
        </a>
    </div>
    <script type="text/javascript">
        //点击广告，记录点击数
        function clickAd(id, url) {
            $.ajax({
                url: '@Url.Action("GetAd","Ad")',
                async: false,
                type: 'POST',
                data: { id: id },
                success: function (result) {
                    window.location.href = url;
                }
            });
        }

    </script>
    <script>
        // 公告滚动
        var speed = 30;//数值越大，速度越慢
        var noticeloop = document.getElementById("noticeloop");
        var noticeinfo = document.getElementById("noticeinfo");
        var notice = document.getElementById("notice");
        function MarqueeLeft() {
            if (noticeloop.offsetWidth - notice.scrollLeft <= 0) {
                notice.scrollLeft -= noticeinfo.offsetWidth
            }
            else { notice.scrollLeft++ }
        }
        var MyMar = setInterval(MarqueeLeft, speed);
        notice.onmouseover = function () {
            clearInterval(MyMar);
        }
        notice.onmouseout = function () {
            MyMar = setInterval(MarqueeLeft, speed);
        }
        //点击红钻动画
        var offset = $("#cartoonend").offset();
        var flag = false;
        var i = 0;
        $(".red").click(function (event) {
            var that = $(this);
            if (flag) return;
            flag = true;

            var flyer = $('<div class="u-flyer"></div>');
            flyer.fly({
                start: {
                    left: event.pageX,
                    top: event.pageY
                },
                end: {
                    left: offset.left + 0,
                    top: offset.top + 30,
                    width: 0,
                    height: 0,
                },
                onEnd: function () {
                    this.destory();
                }
            });
            var length = that.parent().children("div").length;
            var clicknum = $(this).find("span").text()
            var redsum = $("#redsum").text();
            var sum = parseFloat(clicknum) + parseFloat(redsum)
            $("#redsum").text(parseFloat(sum).toFixed(6));  //得到红钻总数量
            var id = $(this).find("p").text();
            //that.remove();
            //if (length == 1) {
            //    if (i == 0) {
            //        $("#red1").hide(); $("#red2").show();
            //        i += 1;
            //    }
            //    else { if (i == 1) { $("#red2").hide(); $("#red3").show(); } }
            //}
            //flag = false;
            //return;
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/Home/GetRed",//url
                data: { Id: id },
                success: function (result) {
                    if (result.result_code == 1000) {
                        that.remove();
                        if (length == 1) {
                            if (i == 0) {
                                $("#red1").hide(); if ($("red2").children("div").length > 0) { $("#red2").show(); } else { window.location.reload(); }
                                i += 1;
                            }
                            else {
                                if (i == 1) {
                                    $("#red2").hide();
                                    if ($("red3").children("div").length > 0) { $("#red3").show(); } else { window.location.reload(); }
                                }
                            }
                        }
                    }
                    else {
                        layer.msg(result.result_msg);
                    }
                    flag = false;
                },
                error: function () {
                    layer.msg("异常！");
                    flag = false;
                }
            });

        });
        //轮播图
        var mySwiper = new Swiper('.swiper-container', {
            autoplay: {
                delay: 3000,
            },
            loop: true,
            // 如果需要分页器
            pagination: {
                el: '.swiper-pagination',
            }
        })
        // 排行榜切换
        $("#switch_ranking").click(function () {
            if ($(this).find(".horseinfo").text() == "按马力排行") {
                $(this).find(".horseinfo").text("按红钻排序");
                $("#horseranking").show();
                $("#redranking").hide();
            }
            else if ($(this).find(".horseinfo").text() == "按红钻排序") {
                $(this).find(".horseinfo").text("按马力排行");
                $("#horseranking").hide();
                $("#redranking").show();
            }
        });
        $('.footer a').click(function () {
            $(this).addClass('on').siblings().removeClass('on');
        });

    </script>
</body>
</html>